Skip to content

[Kotlin Spring] fix: Omit example field if not set#24228

Open
wegendt-bosch wants to merge 2 commits into
OpenAPITools:masterfrom
wegendt-bosch:fix/24227-omit-example
Open

[Kotlin Spring] fix: Omit example field if not set#24228
wegendt-bosch wants to merge 2 commits into
OpenAPITools:masterfrom
wegendt-bosch:fix/24227-omit-example

Conversation

@wegendt-bosch

@wegendt-bosch wegendt-bosch commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #24227.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Stop emitting empty example attributes in Kotlin Spring–generated annotations. Only include example when the schema defines one; removes example = "null" and example = "" from outputs. Fixes #24227.

  • Bug Fixes
    • Overrode AbstractKotlinCodegen#toExampleValue to return null unless schema.example is set, omitting default/empty examples in annotations like @Schema/@ApiModelProperty.
    • Updated KotlinSpringServerCodegenTest expectations and regenerated Kotlin Spring samples so annotations now include only description/required when no example is provided.

Written for commit e2da581. Summary will update on new commits.

Review in cubic

@wegendt-bosch

Copy link
Copy Markdown
Contributor Author

cubic is sorta right: it avoids @Schema(example="null")

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@wegendt-bosch

Copy link
Copy Markdown
Contributor Author

Hm, actually this disables all emits of example = ... I'll try overriding the function toExampleValue

@wegendt-bosch wegendt-bosch force-pushed the fix/24227-omit-example branch from 4b6b056 to 67e597c Compare July 7, 2026 14:04
*/
data class Pet(

@Schema(example = "doggie", required = true, description = "")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works now: example is emitted if set

@wegendt-bosch wegendt-bosch changed the title fix: Omit example field if not set [Kotlin Spring] fix: Omit example field if not set Jul 7, 2026
@wegendt-bosch

Copy link
Copy Markdown
Contributor Author

@karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10) please review :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [Kotlin Spring] Example field is filled when not specified

1 participant